{include file="public/layout" /}
<body class="bodystyle">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back_xin" href="{:url("Weapp/index")}" title="返回"><i class="iconfont e-fanhui"></i></a></a>
            <div class="subject">
                <h3>插件应用</h3>
                <h5></h5>
            </div>
            <ul class="tab-base nc-row">
                {eq name="$Think.const.CONTROLLER_NAME.'@create'|is_check_access" value="1"}
                <li><a href="{:url("Weapp/create")}" class="tab {if condition="in_array($Request.action, array('create'))"}current{/if}"><span>创建插件</span></a></li>
                {/eq}

                {eq name="$Think.const.CONTROLLER_NAME.'@pack'|is_check_access" value="1"}
                <li><a href="{:url("Weapp/pack")}" class="tab {if condition="in_array($Request.action, array('pack'))"}current{/if}"><span>打包插件</span></a></li>
                {/eq}
            </ul>
        </div>
    </div>
    <form class="form-horizontal" id="post_form" action="{:U('Weapp/pack')}" method="post">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="code"><em>*</em>插件标识</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="code" placeholder="比如：Demo" id="code" class="input-txt" onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^a-zA-Z0-9]/g,''));" autocomplete="off">
                    <input type="button" class="btn" value="生成文件列表" onclick="createPackfiles();">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="additional_file"><em>*</em>打包文件列表</label>
                </dt>
                <dd class="opt">
                    <textarea rows="5" cols="80" id="additional_file" name="additional_file" style="width: 375px;height:250px;" placeholder="列举插件涉及的独立文件，尽量不改动原系统代码：
weapp/Sample
template/plugins/sample
application/plugins/controller/Sample.php
application/plugins/logic/SampleLogic.php
application/plugins/model/Sample.php"></textarea>
                    <p class="notic">一行代表一个可选值</p>
                    <p class="">一行代表一个可选值</p>
                </dd>
            </dl>
            <div class="bot"><a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a></div>
        </div>
    </form>
</div>
<script type="text/javascript">

    /*插件标准涉及的文件及目录*/
    var packlistArr = new Array();
    packlistArr[0] = 'weapp/Sample';
    packlistArr[1] = 'template/plugins/sample';
    packlistArr[2] = 'application/plugins/controller/Sample.php';
    packlistArr[3] = 'application/plugins/logic/SampleLogic.php';
    packlistArr[4] = 'application/plugins/model/Sample.php';
    /*--end*/

    /**
     * 插件标识格式判断
     * @param str
     */
    function checkCode(str){
        var reg = /^[A-Z]([a-zA-Z0-9]*)$/;
        if(reg.test(str)){
            return true;
        }else{
            return false;
        }
    }

    // 判断输入框是否为空
    function checkForm(){
        var code = $.trim($('input[name=code]').val());
        if(!checkCode(code)){
            showErrorMsg('插件标识格式不正确！');
            $('input[name=code]').focus();
            return false;
        }
        if ('Sample' == code) {
            showErrorMsg('样本插件禁止打包！');
            $('input[name=code]').focus();
            return false;
        }
        layer_loading('正在处理');
        $('#post_form').submit();
    }

    // 生成打包文件列表
    function createPackfiles()
    {
        var code = $.trim($('input[name=code]').val());
        if(!checkCode(code)){
            showErrorMsg('插件标识格式不正确！');
            $('input[name=code]').focus();
            return false;
        }
        if ('Sample' == code) {
            showErrorMsg('样本插件禁止打包！');
            $('input[name=code]').focus();
            return false;
        }
        var additional_file = '';
        for (var i = 0; i < packlistArr.length; i++) {
            filestr = packlistArr[i];
            filestr = filestr.replace('Sample', code);
            filestr = filestr.replace('sample', code.toLowerCase());
            additional_file += filestr;
            if (i < packlistArr.length - 1) {
                additional_file += "\n";
            }
        }
        $('#additional_file').val(additional_file);
        var index = layer.alert("请检查打包文件或目录是否完整！", {icon: 6, title:false}, function(){
            layer.close(index);
            $('#additional_file').focus();
        });
    }

</script>
{include file="public/footer" /}